package cn.tyf.dao;

import cn.tyf.domain.Notice;
import cn.tyf.domain.Record;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface NoticeDao {

    @Insert("insert into notice(uid,time,theme,content) value(#{uid},#{time},#{theme},#{content})")
    public void addNotice(Notice notice);

    @Select("select admin.`name`,notice.*  from notice left JOIN admin ON admin.id = notice.uid  WHERE 1 = 1 " +
            "        order by notice.time  DESC limit #{arg0},#{arg1}")
    List<Notice> findByPage(Integer start, Integer pageSize);

    @Select("select count(*) from notice")
    Integer findCount();

    @Select("select notice.theme,notice.content from notice where nid = #{nid}")
    Notice findByNotice(Integer nid);

    @Update("update notice set theme=#{theme},time=#{time},content=#{content} where nid = #{nid}")
    void updateNotice(Notice notice);

    @Delete("delete from notice where nid = #{id}")
    void deleteByNid(Integer nid);

    @Select("select admin.`name`,notice.*  from notice left JOIN admin ON admin.id = notice.uid  WHERE 1 = 1" +
            " order by notice.time  DESC")
    List<Notice> finAll();

}
